// 格式化date类型输出,输出格式2020-03-23 15:30
function formatTime(date) {
  var year = date.getFullYear()
  var month = date.getMonth() + 1
  var day = date.getDate()

  var hour = date.getHours()
  var minute = date.getMinutes()
  var second = date.getSeconds()


  return [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute].map(formatNumber).join(':')
}
// 格式化date类型输出,输出格式 03-23 15:30
function formatTimeWithoutYear(date) {
  var year = date.getFullYear()
  var month = date.getMonth() + 1
  var day = date.getDate()
  var hour = date.getHours()
  var minute = date.getMinutes()
  var second = date.getSeconds()
  return [month, day].map(formatNumber).join('-') + ' ' + [hour, minute].map(formatNumber).join(':')
}

function formatNumber(n) {
  n = n.toString()
  return n[1] ? n : '0' + n
}
// 格式化新闻的摘要，超过200字用...代替
function subText(text) {
  if (typeof(text)=="string" && text.length>200){
    return text.substring(0,200)+"..."
  }
  return text
}
module.exports = {
  formatTime: formatTime,
  formatTimeWithoutYear: formatTimeWithoutYear,
  subText: subText
};






